package client.comm.baoding.ui

import android.content.Intent
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.R
import client.comm.baoding.databinding.ActivityAccountSafeBinding
import client.comm.baoding.ui.vm.AccountSafeViewModel
import client.comm.commlib.base.FinishReciver
import client.comm.commlib.toast.toast
import client.comm.commlib.utils.SharedUtil

/**
 * 账户安全
 */
class AccountSafeActivity : BaseMiddleActivity<AccountSafeViewModel, ActivityAccountSafeBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_account_safe
    }

    override fun initViewModel(): AccountSafeViewModel = createViewModel()

    override fun initView() {
        binding?.apply {
            event = this@AccountSafeActivity
            vm = viewModel
        }
    }

    override fun observerUI() {
        viewModel.call.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    toast("注销成功")
                    SharedUtil.clear("token")
                    startActivity(Intent(this, LoginActivity::class.java))
                    sendBroadcast(Intent(FinishReciver.FINISH_ACTION))
                }
            }
        })

    }

}